/*
 * ULSF Sagittarius IDA
 * Copyright (C) 2012, John Pritchard, all rights reserved.
 * 
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package sagittarius.design;

import sagittarius.Field;
import sagittarius.Visualization;

import sagittarius.airfoil.Airfoil;

import json.Json;

import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;


/**
 * {@link sagittarius.Visualization Visualization} operator for the
 * three dimensions of space, X, Y and Z.  This class produces line
 * meshes for the three axes.
 */
public class Axes
    extends Object
    implements Visualization
{
    public enum Domain {
        X, Y, Z;
    }
    public final static class X 
        extends Axes
    {
        public X(){
            super(Domain.X);
        }
    }
    public final static class Y 
        extends Axes
    {
        public Y(){
            super(Domain.Y);
        }
    }
    public final static class Z 
        extends Axes
    {
        public Z(){
            super(Domain.Z);
        }
    }


    public final static float Length = 1.5f*sagittarius.Controller.H;



    private final float[] vertices;

    private final int count;

    private final Domain domain;

    private Mesh mesh;


    protected Axes(Domain d){
        super();
        this.count = 4;
        this.domain = d;
        switch(d){
        case X:
            this.vertices = new float[]{
                -Length,0,0,
                +Length,0,0,
                (Length-0.1f),+0.1f,0,
                (Length-0.1f),-0.1f,0,
            };
            break;
        case Y:
            this.vertices = new float[]{
                0,-Length,0,
                0,+Length,0,
                +0.1f,(Length-0.1f),0,
                -0.1f,(Length-0.1f),0,
            };
            break;
        case Z:
            this.vertices = new float[]{
                0,0,-Length,
                0,0,+Length,
                -0.1f,0,(Length-0.1f),
                +0.1f,0,(Length-0.1f),
            };
            break;
        default:
            throw new Error(d.name());
        }
    }


    public float get(Field field){
        throw new UnsupportedOperationException();
    }
    public float getLength(){
        throw new UnsupportedOperationException();
    }
    public float getRadius(){
        throw new UnsupportedOperationException();
    }
    public float getSpan(){
        throw new UnsupportedOperationException();
    }
    public float getAlpha(){
        throw new UnsupportedOperationException();
    }
    public float getBeta(){
        throw new UnsupportedOperationException();
    }
    public float getGamma(){
        throw new UnsupportedOperationException();
    }
    public float getDelta(){
        throw new UnsupportedOperationException();
    }
    public float getEpsilon(){
        throw new UnsupportedOperationException();
    }
    public float getZeta(){
        throw new UnsupportedOperationException();
    }
    public float getEta(){
        throw new UnsupportedOperationException();
    }
    public float getTheta(){
        throw new UnsupportedOperationException();
    }
    public float getIota(){
        throw new UnsupportedOperationException();
    }
    public float getKappa(){
        throw new UnsupportedOperationException();
    }
    public String getVolume(){
        throw new UnsupportedOperationException();
    }
    public String getAirfoilConfiguration(){
        throw new UnsupportedOperationException();
    }
    public String getAirfoilIdentifier(){
        throw new UnsupportedOperationException();
    }
    public int getCount(){
        return this.count;
    }
    public Mesh getMesh(){
        Mesh mesh = this.mesh;
        if (null == mesh){

            final float[] vertices = this.vertices;

            mesh = new Mesh(Visualization.Static,this.count,0,
                            VertexAttribute.Position());

            mesh.setVertices(vertices);

            this.mesh = mesh;
        }
        return mesh;
    }
    public void dispose(){
        Mesh mesh = this.mesh;
        if (null != mesh){
            this.mesh = null;

            mesh.dispose();
        }
    }
    public void generate(){
    }
    public void terminal(){
    }
    public boolean waitfor(){
        return true;
    }
    public void list(){

        System.out.println("#");
        System.out.println("# Axis data listing");
        System.out.println("#");
        System.out.println("# [vertex_index] (a_position)");
        System.out.println("#");

        final float[] vertices = this.vertices;
        final int verticesCount = this.getCount();

        float[] a_position = new float[2];

        for (int vv = 0, ofs; vv < verticesCount; vv++){
            ofs = (vv*3);
            System.arraycopy(vertices,ofs,a_position,0,2);

            System.out.printf("[%d] (%2.2g,%2.2g,%2.2g)%n",vv,a_position[0],a_position[1]);
        }
    }
    public String toString(){
        return this.domain.name();
    }
    public Json toJson(){
        throw new UnsupportedOperationException();
    }
    public boolean fromJson(Json json){
        throw new UnsupportedOperationException();
    }
}
